function getUrlParameter(name) {
	var results = new RegExp('[\\?&]' + name + '=([^&#]*)').exec(window.location.href);
	if (results === null) {
		return null;
	} else {
		return decodeURIComponent(results[1] || 0);
	}
}

function getContextPath() {
	return $("#contextPath").text();
}

function getTemplate(templateName) {
	var templateContainer = $(".templateContainer");
	
	var template = $("#" + templateName, templateContainer).clone();
	template.attr("id", templateName.replace("Template", ""));
	
	return template;
}

function showMessage(message, closeCallBack) {
	$("<div><p>" + message + "</p></div>").dialog({
		dialogClass : "noclose noTitleBar",
		closeOnEscape : true,
		modal : true,
		resizable : false,
		draggable : false,
		buttons : [ {
			id : "okButton",
			text : "Ok",
			click : function() {
				$(this).dialog("close");
			}
		} ],
		close : function() {
			$(this).remove();
			if (closeCallBack) {
				closeCallBack();
			}
		}
	});
}

function showErrorMessage(message, closeCallBack) {
	$("<div><p class='error'>" + message + "</p></div>").dialog({
		dialogClass : "noclose noTitleBar",
		closeOnEscape : true,
		modal : true,
		resizable : false,
		draggable : false,
		buttons : [ {
			id : "okButton",
			text : "Ok",
			click : function() {
				$(this).dialog("close");
			}
		} ],
		close : function() {
			$(this).remove();
			if (closeCallBack) {
				closeCallBack();
			}
		}
	});
}

function showSpinningWheel() {
	getTemplate("spinningWheelDialogTemplate").dialog({
		dialogClass : "noclose noTitleBar",
		closeOnEscape : true,
		modal : true,
		resizable : false,
		draggable : false,
		buttons : [],
		close : function() {
			$(this).remove();
		}
	});
}

function redirectToLoginPage() {
	window.location.replace(window.location.protocol + "//" + window.location.host + getContextPath() + "/index.jsp");
}